﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
using System.Threading;

namespace MiageMetroPaquitoNodeServer
{
    public class setup
    {

        static void Main(string[] args)
        {
            
            System.Console.WriteLine("Start set up Node JS Server");
            Process[] nodes = Process.GetProcessesByName("node");

            Console.WriteLine("{0} nodes processes", nodes.Length);
	        Thread.Sleep(5000);
            return;
            
            if (System.IO.File.Exists("./Server.js"))
            {
                try
                {
                    File.Delete("./Server.js");
                } 
                catch 
                {
                    Console.WriteLine("Internal Error");
                    return; 
                }
                //return;
            }

            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            System.IO.StreamWriter file = new System.IO.StreamWriter("./node.bat");

            try
            {
                                
                //The code below will write lines to the .bat file.
                //The dir command is used in a Command to list files in the specified directory.
                //The > command in this case sends the list to a text file.
                file.WriteLine(@"dir C:\Zip\*.zip > C:\bat\dir.txt");
                file.WriteLine("exit");
                file.Close();

                //The System.Dignostics.Process Process Class allows a Visual Studio Program
                //to execute another application              

                proc = new System.Diagnostics.Process();

                proc.EnableRaisingEvents = false;
                //This line executes the .bat file created above.
                proc.StartInfo.FileName = @"C:\bat\dirlist.bat";
                proc.Start();
            }
            catch (System.Exception err)
            {
                Console.WriteLine("Exception Occured : " + err.Message);                
            }
            finally
            {
                proc.Close();

            }
        }

    }
}